package com.homwee.serialportinspection.model;

import android.os.Message;

import java.util.ArrayList;
import java.util.List;

public abstract class Controller {
    protected List<Listener> mListeners = new ArrayList();

    public interface Listener {
        boolean onRequest(Controller controller, Message request);
    }

    public abstract boolean start();

    public abstract boolean stop();

    public abstract Message getRequest();

    public abstract boolean sendResponse(Message response);

    public boolean registerListener(Listener listener) {
        if (mListeners.contains(listener)) {
            return false;
        } else {
            mListeners.add(listener);
            return true;
        }
    }

    public boolean unregisterListener(Listener listener) {
        if (mListeners.contains(listener)) {
            mListeners.remove(listener);
            return true;
        } else {
            return true;
        }
    }
}
